package com.forfunnet.minjian.rest;

import com.forfunnet.minjian.message.request.BaseRequest;
import com.forfunnet.minjian.message.request.ChangePasswordRequest;
import com.forfunnet.minjian.message.request.LoginRequest;
import com.forfunnet.minjian.message.request.RegisterRequest;
import com.forfunnet.minjian.message.response.AdsListResponse;
import com.forfunnet.minjian.message.response.BaseResponse;
import com.forfunnet.minjian.message.response.LoginResponse;
import com.forfunnet.minjian.message.response.ProductDetailResponse;
import com.forfunnet.minjian.message.response.ProductListResponse;
import com.forfunnet.minjian.message.response.RegisterResponse;

import org.androidannotations.rest.spring.annotations.Body;
import org.androidannotations.rest.spring.annotations.Delete;
import org.androidannotations.rest.spring.annotations.Get;
import org.androidannotations.rest.spring.annotations.Path;
import org.androidannotations.rest.spring.annotations.Post;
import org.androidannotations.rest.spring.annotations.Put;
import org.androidannotations.rest.spring.annotations.RequiresCookie;
import org.androidannotations.rest.spring.annotations.Rest;
import org.androidannotations.rest.spring.annotations.SetsCookie;
import org.androidannotations.rest.spring.api.RestClientErrorHandling;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * Created by RexQian on 2014/12/9.
 */
@Rest(rootUrl = "http://192.168.1.104",
//@Rest(rootUrl = "http://121.41.89.246:8180",
        converters = {MappingJackson2HttpMessageConverter.class,
                ByteArrayHttpMessageConverter.class,
                FormHttpMessageConverter.class,
                StringHttpMessageConverter.class})
public interface MyRestClient extends RestClientErrorHandling {

    public RestTemplate getRestTemplate();
    public void setRestTemplate(RestTemplate template);

    void setRootUrl(String rootUrl);
    String getRootUrl();

    void setCookie(String name, String value);
    String getCookie(String name);

    @Post("/test")
    BaseResponse post(@Body BaseRequest request);

    @Post("/login.json")
    @SetsCookie({"ss-id"})
    LoginResponse login(@Body LoginRequest request);
//
//    @Post("/qqLogin.json")
//    @SetsCookie({"ss-id"})
//    LoginResponse qqLogin(ThirdPartyLoginRequest request);
//
//    @Post("/weiboLogin.json")
//    @SetsCookie({"ss-id"})
//    LoginResponse weiboLogin(ThirdPartyLoginRequest request);
//
//    @Post("/wechatLogin.json")
//    @SetsCookie({"ss-id"})
//    LoginResponse wechatLogin(ThirdPartyLoginRequest request);
//
    @Post("/register.json")
    @SetsCookie({"ss-id"})
    RegisterResponse register(@Body RegisterRequest request);

    @Post("/password.json")
    BaseResponse changePassword(@Body ChangePasswordRequest request);
//
//    @Post("/users/{id}.json")
//    @RequiresCookie("ss-id")
//    BaseResponse changeUserInfo(int id, ChangeUserInfoRequest request);
//
//    @Put("/users/{id}/headimage.json")
//    @RequiresCookie("ss-id")
//    BaseResponse updateHead(int id, MultiValueMap<String, Object> data);

    @Get("/imageAds.json")
    @RequiresCookie("ss-id")
    AdsListResponse getAdsList();

    @Get("/products.json?Offset={offset}&Limit={limit}&FilterOwnerId={ownerId}" +
            "&FilterName={name}&FilterFavorite={favorite}")
    @RequiresCookie("ss-id")
    ProductListResponse getProductList(@Path int offset, @Path int limit,
                                       @Path Integer ownerId, @Path String name,
                                       @Path boolean favorite);

    @Get("/products/{productId}")
    @RequiresCookie("ss-id")
    ProductDetailResponse getProductDetail(@Path int productId);

    @Put("/favorites.json?ProductId={productId}")
    @RequiresCookie("ss-id")
    BaseResponse addProductFavorite(@Path int productId);

    @Delete("/favorites.json?ProductId={productId}")
    @RequiresCookie("ss-id")
    BaseResponse removeProductFavorite(@Path int productId);
}
